package com.ruitu.health_2.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ruitu.arad.base.BaseFragment;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.health_2.R;
import com.ruitu.health_2.ui.common.VideoDetailActivity;
import com.ruitu.health_2.ui.common.VideoListActivity;
import com.ruitu.router_module.bean.product.Video;
import com.ruitu.router_module.bean.product.VideoDetial;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

// 视频详情页面播放器下方第一个tab对应的fragment  推荐相关视频列表
public class VideoDetail1Fragment extends BaseFragment {
    private RecyclerView rcv_list;

    private static List<Video> videoList = new ArrayList<>();// 视频列表
    VideoListActivity.VideoListAdapter adapter;

    public static VideoDetail1Fragment newInstance(VideoDetial detial) {

        VideoDetail1Fragment.videoList = detial.getVideosOtherByModel();

        Bundle args = new Bundle();
        VideoDetail1Fragment fragment = new VideoDetail1Fragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        adapter = new VideoListActivity.VideoListAdapter(getActivity());
        adapter.setOnItemClickListener(new ListBaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View itemView, int position) {
                VideoDetailActivity activity = (VideoDetailActivity) getActivity();
                if (null != activity) {
                    activity.stop();
                    activity.reqData(videoList.get(position).getId());
                }
            }
        });
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_video_detail1, container, false);
        rcv_list = v.findViewById(R.id.rcv_list);

        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        rcv_list.setLayoutManager(manager);
        rcv_list.setAdapter(adapter);
        adapter.setDataList(videoList);

        return v;
    }
}
